package summer;

import java.awt.Dimension;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author jiangz
 * @since  2020年7月13日 下午4:33:57
 *
 *
 */
public class Message extends JPanel {

    private static final long serialVersionUID = 1L;

    private String sayto;
    private String sayer;
    private long time;
    private String content;

    public Message(String sayto, String sayer, long time, String content) {
        super();
        this.sayto = sayto;
        this.sayer = sayer;
        this.time = time;
        this.content = content;

        BoxLayout layout= new BoxLayout(this, BoxLayout.Y_AXIS);
        this.setLayout(layout);
        this.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));

        this.setMaximumSize(new Dimension(360, 100000));

        if(Objects.equals(sayto, sayer)) {
            // 发送人为当前对话对象
            this.add(new JLabel(
                    new SimpleDateFormat("yyy-MM-dd HH:mm:ss  ").format(new Date(time)) + sayer));
            this.add(new JLabel("<html>" + this.content + "</html>"));
        } else {
            // 发送人不是当前对象，因为只考虑单人聊天，所以假定发送人是自己
        }

        this.add(new JLabel(
                new SimpleDateFormat("yyy-MM-dd HH:mm:ss  ").format(new Date(time)) + sayer));
        this.add(new JLabel("<html>" + this.content + "</html>"));
    }

    public String getSayto() {
        return sayto;
    }

    public void setSayto(String sayto) {
        this.sayto = sayto;
    }

    public String getSayer() {
        return sayer;
    }

    public void setSayer(String sayer) {
        this.sayer = sayer;
    }

    public long getTime() {
        return this.time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public String getContent() {
        return this.content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
